<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';
$smarty->compile_check = true;
$smarty->display('header.tpl');


$where = " AND a.app_recruitid = '".$_SESSION['uid']."' ";
//search result
if(trim($_GET[action]) == 'search'){
    $arr = array();
	if(trim($_GET['name'])!=''){ $arr[] = "( b.re_fname  like '%".trim($_GET['name'])."%' OR b.re_lname  like '%".trim($_GET['name'])."%' )";}	
	if(trim($_GET['jobposter'])!=''){ $arr[] = "( d.jo_copname like '%".trim($_GET['jobposter'])."%' )";}	
	if(trim($_GET['date']) !='' ){ $arr[] = " FROM_UNIXTIME(a.app_regtime,'%m/%d/%Y') = '".trim($_GET['date'])."' ";}	
	if(trim($_GET['nickname'])!=''){ $arr[] = "( b.re_nickname  like '%".trim($_GET['nickname'])."%' )";}	
	if(trim($_GET['jobtitle'])!=''){ $arr[] = "( d.jo_title  like '%".trim($_GET['jobtitle'])."%' )";}	
	if(trim($_GET['jobid'])!=''){ $arr[] = "( d.jo_id  = '".trim($_GET['jobid'])."' )";}	
	if(trim($_GET['recruiter'])!=''){ 
		$sql = "SELECT rc_id FROM pa_recuiter WHERE rc_fname like '%".trim($_GET['recruiter'])."%' OR rc_lname like '%".trim($_GET['recruiter'])."%'";
		$recIds = $DB->fetch_all($sql);
		if(!empty($recIds)){
			foreach($recIds as $id){
				$arrIds[] = $id['rc_id'];
			}
			$Ids = @implode(',',$arrIds);
			$arr[] = " ( b.re_usertype = 'recruiter' AND b.re_uid IN (".$Ids.") ) ";
		} 
	}

	if(!empty($arr)){
		$implode  = @implode("AND", $arr);
		$implode  = " AND ".$implode;
		$where    .= $implode;
	}
	$smarty->assign("s",$_GET);
}


$nav = new buildNav;
$nav->limit = "25";


$sql ="SELECT COUNT(*) AS count FROM pa_applicant as a ,pa_resume as b, pa_job as d  WHERE  d.jo_id = a.app_jobid AND a.app_resumeid = b.re_id $where ";

$total = $DB->fetch_one_array($sql);
$nav->total_result = $total[count];

$by    = "app_regtime"; 
$order = "DESC" ;
if($_GET[tp]==1){
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;$_GET[order8]==''&&$order8=1;$_GET[order9]==''&&$order9=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "b.re_fname";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "b.re_nickname";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "d.jo_title";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "d.jo_copname";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "a.app_regtime";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "d.jo_id";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr",$order_arr);
		$smarty->assign("image_arr",$image_arr);

}


$sql ="SELECT * FROM pa_applicant as a ,pa_resume as b,pa_job as d  WHERE  d.jo_id = a.app_jobid AND a.app_resumeid = b.re_id   $where ";

$nav->execute($sql." ORDER BY  $by $order");

$page = $nav->pagenav();


$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
	   $datajob[$i] = $list2;
	   $datajob[$i]['app_regtime'] = date("m/d/Y",$list2['app_regtime']);
	   $i++;
}
//print_r($datajob[0]);
$smarty->assign("jobdetail",$datajob[0]);
$smarty->assign("tpp",$_GET[tpp]);

$smarty->assign("applist",$datajob);

$smarty->assign("page",$page);
if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("job_id",$job_id);
$smarty->assign("appnum", $total[count]);
$smarty->display('allleft.tpl');

$smarty->display('mysubmitted.tpl');

$smarty->display('footer.tpl');
?>